//package com.pug.security.handler;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Component;
//
///**
// * @author RenGaoshuai
// * @date 2023/7/17 10:56
// * @description 自定义认证处理器
// */
//@Component
//public class MyAuthenticationProvider implements AuthenticationProvider {
//
//    @Autowired
//    private UserDetailsService userDetailsService;
//    @Autowired
//    private PasswordEncoder bCryptPasswordEncoder;
//
//    //认证用户
//    @Override
//    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//        //获取页面输入的账号密码
//        String username = authentication.getName();
//        String rawPassword = authentication.getCredentials().toString();
//
//        //在这里你可以完成自己想完成的事情
//        UserDetails userDetails = userDetailsService.loadUserByUsername(username);
//
//        return checkePassword(userDetails, rawPassword, bCryptPasswordEncoder);
//    }
//
//    @Override
//    public boolean supports(Class<?> aClass) {
//        return true;
//    }
//
//    private Authentication checkePassword(UserDetails user, String rawPassword, PasswordEncoder passwordEncoder) {
//        if (passwordEncoder.matches(rawPassword, user.getPassword())) {
//            return new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities());
//        }
//
//        throw new BadCredentialsException("bad authentication");
//    }
//}
